//https://blog.csdn.net/sinat_36728518/article/details/106280722
//https://blog.csdn.net/qq_39223195/article/details/106287522
//https://zhuanlan.zhihu.com/p/298189197
//https://www.cnblogs.com/lou-0820/p/13704454.html
//问题1：
//craco-alias是啥
//问题2
//为什么编译的时候tsconfig.json paths 字段会消失
const path = require('path')
const resolve = dir => path.resolve(__dirname, dir)

const CracoAntDesignPlugin = require("craco-antd");

module.exports = {
  webpack: {
    alias: {
      '@': resolve('src'),
      'components': resolve('src/components'),
      'styles': resolve('src/styles'),
      'constants':resolve('src/constants'),
      'assets':resolve('src/assets'),
      'apis':resolve('src/apis'),
      'helpers':resolve('src/helpers'),
      'hooks':resolve('src/hooks'),
      'reducers':resolve('src/reducers'),
    },
  },
  plugins: [
    {
      plugin: CracoAntDesignPlugin,
      options: {
        lessLoaderOptions: {
          lessOptions: {
            javascriptEnabled: true,
            sourceMap: false,
          },
        },
        cssLoaderOptions: {
          modules: {
            localIdentName: '[local]_[hash:base64:5]',
            // 回调必须返回 `local`，`global`，或者 `pure`
            mode: (resourcePath) => {
              if (/pure\.(less|css)$/i.test(resourcePath)) {
                return 'pure'
              }

              if (/(global)\.(less|css)$/i.test(resourcePath)) {
                return 'global'
              }

              if (/antd/i.test(resourcePath)) {
                return 'global'
              }

              return 'local'
            },
          },
        },
        babelPluginImportOptions: {
          libraryName: 'antd',
          libraryDirectory: 'es',
          style: true,
        },
      },
    }
  ],
  babel: {   //用来支持装饰器
    plugins: [["@babel/plugin-proposal-decorators", { legacy: true }]]
  },
}
